package com.deyuanyun.pic.ctrl.controller.dto;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.common.util.web.Asserts;
import com.deyuanyun.pic.ctrl.domain.CpRecTask;
import com.deyuanyun.pic.settings.controller.pipe.vo.PipeLocationDTO;
import com.deyuanyun.pic.settings.domain.base.Attachment;
import com.deyuanyun.pic.settings.domain.pipe.PipeLine;
import com.deyuanyun.pic.settings.service.base.AttachmentService;
import com.deyuanyun.pic.settings.service.pipe.PipeLineService;
import com.deyuanyun.pic.settings.service.pipe.PipeLocationService;

/**
 * 阴保整改项目前台需要的数据DTO。
 * 
 * @author ChenKui
 * @date 2016-06-20
 *
 */
public class CathRepairTaskDTO extends CpRecTask{


    private String pipeLineName;//管道名称

    private String fromPointName;//起点名称
    private String toPointName;//起点名称
    
    private Boolean includeReport;//包含报告
    
    public String getPipeLineName() {
        if(pipeLineName == null){
            PipeLineService pipeLineService = SpringAppliction.getBean(PipeLineService.class);
            String pipeLineId = getPipeLineId();
            if(StringUtils.isNotEmpty(pipeLineId)){
                PipeLine pipeLine = pipeLineService.selectByPrimaryKeyCache(getPipeLineId());
                pipeLineName = pipeLine.getName();
            }
        }
        return pipeLineName;
    }
    
    //获取起点位置名称
    public String getFromPointName() {
        if(StringUtils.isNotEmpty(fromPointName)){
            return fromPointName;
        }
        String pipeLineId = getPipeLineId();
        String fromPointId = getFromPointId();
        if(StringUtils.isEmpty(fromPointId)){
            return fromPointName;
        }
        PipeLocationService pipeLocationService = (PipeLocationService)SpringAppliction.getBean(PipeLocationService.class);
        PipeLocationDTO pipeLocation = pipeLocationService.queryPipeLocationById(pipeLineId,fromPointId);
        Asserts.assertTrue(pipeLocation != null, "没有找到起点编号对应的桩或者场站阀室、" + fromPointId);
        fromPointName = pipeLocation.getName();
        return fromPointName;
    }

    //获取终点位置名称
    public String getToPointName() {
        if(StringUtils.isNotEmpty(toPointName)){
            return toPointName;
        }
        String pipeLineId = getPipeLineId();
        String toPointId = getToPointId();
        if(StringUtils.isEmpty(toPointId)){
            return toPointName;
        }
        PipeLocationService pipeLocationService = (PipeLocationService)SpringAppliction.getBean(PipeLocationService.class);
        PipeLocationDTO pipeLocation = pipeLocationService.queryPipeLocationById(pipeLineId,toPointId);
        Asserts.assertTrue(pipeLocation != null, "没有找到终点编号对应的桩或者场站阀室、" + toPointId);
        toPointName = pipeLocation.getName();
        return toPointName;
    }

    public Boolean getIncludeReport() {
        if(includeReport == null){
            AttachmentService attachmentService = SpringAppliction.getBean(AttachmentService.class);
            String businessId = getId();
            Attachment attachment = attachmentService.queryAttachmentByCustomOne(businessId, "CP_REC_RECODE_REPORT");
            includeReport = attachment != null;
        }
        return includeReport;
    }
    
    
    
}
